package com.study.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.{SparkConf, SparkContext}

object Scala03_RDD_Operator_Transform {
  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setMaster("local[*]").setAppName("RDD")
    val sc = new SparkContext(conf)

    // TODO 算子 - 转换 - mapPartitionsWithIndex
    val rdd = sc.makeRDD(List(1,2,3,4,5,6),3)
    // [1,2] [3,4] [5,6]
    // 单独取一个分区的数据
    val rdd1 = rdd.mapPartitionsWithIndex(
      (index, list) => {
        if (index == 1) {
          list
        } else {
          Nil.iterator
        }
      }
    )
    rdd1.collect().foreach(println)
    /*
    3
    4
     */

    sc.stop()



  }

}
